package org.lzy.shop.util

object CityDataManager {
    // 省份列表
    val provinces: List<String> = listOf(
        "北京市", "上海市", "天津市", "重庆市", "河北省", "山西省", "内蒙古自治区",
        "辽宁省", "吉林省", "黑龙江省", "江苏省", "浙江省", "安徽省", "福建省",
        "江西省", "山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区",
        "海南省", "四川省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省",
        "青海省", "宁夏回族自治区", "新疆维吾尔自治区", "香港特别行政区", "澳门特别行政区", "台湾省"
    )

    // 城市数据映射
    private val cityMap: Map<String, List<String>> = mapOf(
        "北京市" to listOf("北京市"),
        "上海市" to listOf("上海市"),
        "天津市" to listOf("天津市"),
        "重庆市" to listOf("重庆市"),
        "江苏省" to listOf("南京市", "无锡市", "徐州市", "常州市", "苏州市", "南通市", "连云港市", "淮安市", "盐城市", "扬州市", "镇江市", "泰州市", "宿迁市"),
        "浙江省" to listOf("杭州市", "宁波市", "温州市", "嘉兴市", "湖州市", "绍兴市", "金华市", "衢州市", "舟山市", "台州市", "丽水市"),
        "广东省" to listOf("广州市", "深圳市", "珠海市", "汕头市", "佛山市", "韶关市", "湛江市", "肇庆市", "江门市", "茂名市", "惠州市", "梅州市", "汕尾市", "河源市", "阳江市", "清远市", "东莞市", "中山市", "潮州市", "揭阳市", "云浮市"),
        // 添加了主要省份的城市数据
    )

    // 区县数据映射
    private val districtMap: Map<String, Map<String, List<String>>> = mapOf(
        "上海市" to mapOf(
            "上海市" to listOf("黄浦区", "徐汇区", "长宁区", "静安区", "普陀区", "虹口区", "杨浦区", "浦东新区", "闵行区", "宝山区", "嘉定区", "金山区", "松江区", "青浦区", "奉贤区", "崇明区")
        ),
        "北京市" to mapOf(
            "北京市" to listOf("东城区", "西城区", "朝阳区", "丰台区", "石景山区", "海淀区", "门头沟区", "房山区", "通州区", "顺义区", "昌平区", "大兴区", "怀柔区", "平谷区", "密云区", "延庆区")
        ),
        "天津市" to mapOf(
            "天津市" to listOf("和平区", "河东区", "河西区", "南开区", "河北区", "红桥区", "东丽区", "西青区", "津南区", "北辰区", "武清区", "宝坻区", "滨海新区", "宁河区", "静海区", "蓟州区")
        ),
        "重庆市" to mapOf(
            "重庆市" to listOf("万州区", "涪陵区", "渝中区", "大渡口区", "江北区", "沙坪坝区", "九龙坡区", "南岸区", "北碚区", "綦江区", "大足区", "渝北区", "巴南区", "黔江区", "长寿区", "江津区", "合川区", "永川区", "南川区", "璧山区", "铜梁区", "潼南区", "荣昌区", "开州区", "梁平区", "武隆区", "城口县", "丰都县", "垫江县", "忠县", "云阳县", "奉节县", "巫山县", "巫溪县", "石柱土家族自治县", "秀山土家族苗族自治县", "酉阳土家族苗族自治县", "彭水苗族土家族自治县")
        ),
        "江苏省" to mapOf(
            "南京市" to listOf("玄武区", "秦淮区", "建邺区", "鼓楼区", "浦口区", "栖霞区", "雨花台区", "江宁区", "六合区", "溧水区", "高淳区"),
            "苏州市" to listOf("姑苏区", "虎丘区", "吴中区", "相城区", "吴江区", "昆山市", "常熟市", "张家港市", "太仓市")
        ),
        "浙江省" to mapOf(
            "杭州市" to listOf("上城区", "下城区", "江干区", "拱墅区", "西湖区", "滨江区", "萧山区", "余杭区", "富阳区", "临安区", "桐庐县", "淳安县", "建德市"),
            "宁波市" to listOf("海曙区", "江北区", "北仑区", "镇海区", "鄞州区", "奉化区", "象山县", "宁海县", "余姚市", "慈溪市")
        )
    )

    /**
     * 根据省份获取城市列表
     */
    fun getCitiesByProvince(province: String): List<String> {
        return cityMap[province] ?: listOf("市辖区")
    }

    /**
     * 根据省份和城市获取区县列表
     */
    fun getDistrictsByProvinceAndCity(province: String, city: String): List<String> {
        return districtMap[province]?.get(city) ?: listOf("县/区")
    }

    /**
     * 获取默认的省份位置
     */
    fun getDefaultProvincePosition(): Int {
        return provinces.indexOf("江苏省")
    }

    /**
     * 获取默认的城市位置
     */
    fun getDefaultCityPosition(province: String): Int {
        val cities = getCitiesByProvince(province)
        return when (province) {
            "江苏省" -> cities.indexOf("苏州市")
            "上海市" -> cities.indexOf("上海市")
            "北京市" -> cities.indexOf("北京市")
            "天津市" -> cities.indexOf("天津市")
            "重庆市" -> cities.indexOf("重庆市")
            else -> 0
        }
    }

    /**
     * 获取默认的区县位置
     */
    fun getDefaultDistrictPosition(province: String, city: String): Int {
        val districts = getDistrictsByProvinceAndCity(province, city)
        return when {
            province == "江苏省" && city == "苏州市" -> districts.indexOf("昆山市")
            province == "上海市" && city == "上海市" -> districts.indexOf("浦东新区")
            province == "北京市" && city == "北京市" -> districts.indexOf("朝阳区")
            province == "天津市" && city == "天津市" -> districts.indexOf("和平区")
            province == "重庆市" && city == "重庆市" -> districts.indexOf("渝中区")
            else -> 0
        }
    }
}